<template>
  <a-card :bordered="false">
      <a-divider orientation="left"><h1>结余结算</h1></a-divider>
      <div class="table-page-search-wrapper">
        <a-form layout="inline">
          <a-row :gutter="24">
            <a-col :md="6" :sm="12">
              <a-form-item label="">
                <a-select v-model="queryParam.station" placeholder="请选择加油站" @change="jySearch">
                  <a-select-option value="">请选择加油站</a-select-option>
                  <a-select-option v-for="(item, key) in stationOptions" :key="key" :value="item.id">
                    {{ item.realname }}
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
          </a-row>
        </a-form>
        <a-row :gutter="24">
          <a-col :md="12" :sm="12">
            <my-card :loading="loading" title="微信(元)" :total="wxTotal"> </my-card>
          </a-col>
          <a-col :md="12" :sm="12">
            <my-card :loading="loading" title="支付宝(元)" :total="zfbTotal"> </my-card>
          </a-col>
        </a-row>
      </div>
    <br />
    <br />
    <a-divider orientation="left"><h1>结算历史</h1></a-divider>
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="24">

          <a-col :md="6" :sm="8">
            <a-form-item label="支付渠道">
              <j-dict-select-tag  v-model="queryParam.hl" placeholder="" :type="'select'" dictCode="pay_type" />
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="汇款结果">
              <j-dict-select-tag  v-model="queryParam.status" placeholder="" :type="'select'" dictCode="settle_status" />
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :md="10" :sm="12">
              <a-form-item label="日期" :labelCol="{span: 5}" :wrapperCol="{span: 18, offset: 1}">
                <j-date v-model="queryParam.settleTime_begin" :showTime="false" date-format="YYYY-MM-DD HH:mm:ss" style="width:45%" placeholder="请选择开始时间" ></j-date>
                <span style="width: 10px;">~</span>
                <j-date v-model="queryParam.settleTime_end" :showTime="false" date-format="YYYY-MM-DD HH:mm:ss" style="width:45%" placeholder="请选择结束时间"></j-date>
              </a-form-item>
            </a-col>
          </template>
          <a-col :md="6" :sm="8">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button type="primary" icon="download" @click="handleExportXls('结算')">导出</a-button>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table ref="table" size="middle" bordered rowKey="id" :columns="columns" :dataSource="dataSource" :pagination="ipagination"
        :loading="loading" :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}" @change="handleTableChange">
      </a-table>
    </div>
    <!-- table区域-end -->

  </a-card>
</template>

<script>
  import {
    JeecgListMixin
  } from '@/mixins/JeecgListMixin'
  import {
    listAllOil, getOrderAmountData
  } from '@/api/api'
  import MyCard from '@/components/MyCard'
  import JDate from '@/components/jeecg/JDate'
  export default {
    name: "OrderSettleList",
    mixins: [JeecgListMixin],
    components: { MyCard, JDate },
    data() {
      return {
        description: '结算管理页面',
        stationOptions: [],
        loading: true,
        wxTotal: 0,
        zfbTotal: 0,
        // 表头
        columns: [{
            title: '序号',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: "center",
            customRender: function(t, r, index) {
              return parseInt(index) + 1;
            }
          },
          {
            title: '订单号',
            align: "center",
            dataIndex: 'orderNo'
          },
          {
            title: '结算类型',
            align: "center",
            dataIndex: 'settleType_dictText'
          },
          {
            title: '结算单号',
            align: "center",
            dataIndex: 'settleNo'
          },
          {
            title: '账单金额',
            align: "center",
            dataIndex: 'accountAmount'
          },
          {
            title: '结算金额',
            align: "center",
            dataIndex: 'settleAmount'
          },
          {
            title: '汇路',
            align: "center",
            dataIndex: 'hl'
          },
          {
            title: '账户名称',
            align: "center",
            dataIndex: 'accountName'
          },
          {
            title: '汇款结果',
            align: "center",
            dataIndex: 'status_dictText'
          },
        ],
        url: {
          list: "/lww/orderSettle/list",
          exportXlsUrl: "lww/orderSettle/exportXls",
        },
      }
    },
    computed: {

    },
    created() {
      this.initOilList();
      this.initOrderAmountData();
    },
    methods: {
      initOilList() {
        listAllOil().then(res => {
          if (res.success) {
            this.stationOptions = res.result
          }
        })
      },
      initOrderAmountData(oilId) {
        getOrderAmountData({oilId: oilId}).then(res => {
          if (res.success) {
            if(res.result) {
              this.wxTotal = res.result.wxOrderTotal
              this.zfbTotal = res.result.zfbOrderTotal
            } else {
              this.wxTotal = 0;
              this.zfbTotal = 0;
            }
          }
        })
      },
      jySearch(v) {
        this.initOrderAmountData(v);
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>
